OPENOCD_SCRIPT_DIR := "/usr/share/openocd/scripts/"
OPENOCD_BIN_DIR := ""
FW_BUILD_DIR := "./build/"

DEBUGGER_FILE := "/usr/share/openocd/scripts/interface/stlink.cfg"
# DEBUGGER_FILE := "./lib/emcppbase/openocd/jlink-swd.cfg"

default: fw

all: fw

fw debug="1":
    make

flash elf="build/STM32G030F6P6.elf": (fw "1")
    {{ OPENOCD_BIN_DIR }}openocd \
        -f {{ DEBUGGER_FILE }} \
        -f {{ OPENOCD_SCRIPT_DIR }}/target/stm32g0x.cfg \
        -c init \
        -c "reset halt" \
        -c "flash write_image erase {{ elf }}" \
        -c reset \
        -c exit

clean:
    rm -rf build
